<template>
	<view :class="[config.style]">
		<!--数据列表部分-->
		<view class="list-section uni-clearfix">
			<!-- top="xxx"下拉布局往下偏移,防止被悬浮菜单遮住 -->
			<mescroll-uni ref="mescrollRef" @init="mescrollInit" top="0" :down="downOption" @down="downCallback" @up="upCallback">
				<!-- 数据列表 -->
				<view class="list">
					<view class="item" v-for="(item,index) in list" :key="index" >
						<view class="base-info">
							<view class="orderno">
								<text>订单号：</text>
								<text>{{item.order_no}}</text>
							</view>
							<view class="evaluate" v-if="paid == 1">
								<text>评价</text>
							</view>
						</view>
						<view class="content">
							<view class="cover">
								<image mode="widthFix" :src="item.knowledge_info.cover_200" @error="imageError" class="image"></image>
							</view>
							<view class="info">
								<view class="title text-ellipsis-2">{{item.knowledge_info.title}}</view>
								<view class="description text-ellipsis">{{item.knowledge_info.description}}</view>
								<view class="price">
									<text class="price-title">实付金额：</text>
									<text class="value">￥ {{item.order_info.price == 0 ? '免费':item.order_info.price}}</text>	
								</view>
							</view>
						</view>
						<view class="pay-info">
							<viwe class="pay-yes" v-if="paid == 1">
								<view class="paid-price">
									<text>实付：</text>
									<text>￥ {{item.paid_fee}}</text>
								</view>
								<view class="paid-time">
									<text>支付时间：</text>
									<text>{{item.paid_time_str}}</text>
								</view>
							</viwe>
							<viwe class="pay-yes" v-if="paid == 0">
								<view class="paid-price">
									<text>应付：</text>
									<text>￥ {{item.paid_fee}}</text>
								</view>
								<view class="pay-btn">
									<button type="default" size="mini" @click="sale(item.order_info_id,item.order_info_type)">{{config.sale_btn.before}}</button>
								</view>
							</viwe>
						</view>
					</view>
				</view>
			</mescroll-uni>
		</view>
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	
	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)

		data() {
			return {
				page: 1, //当前页码
				list: [], // 订单列表
				downOption: {
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption:{
					// page: {
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty:{
						tip: '~ 搜索无数据 ~', // 提示
						btnText: '去看看'
					}
				},
			}
		},
		created() {

		},
		computed: {
			...mapState(['config'])
		},
		methods: {
			/**
			 * 获取配置
			 */
			getConfig: function(){
				let that = this
				const config = uni.getStorageSync('config');
				if(config){
					that.config = config
				}else{
					//获取全局配置
					let url = ''
						//#ifdef MP-WEIXIN
						url = 'entry/wxapp/config'
						//#endif
						//#ifdef H5
						url = 'entry/site/config'
						//#endif
					this.util.request({
						url : url,
						data: {
							'action' : 'config'
						},
						success: function (res) {
							if (res.data.code == 200) {
								that.config = res.data.data
							}
						}
					})
				}
			},
			//上拉加载的回调
			upCallback: function() {
				let that = this
				let data = {}
					data.action = 'orders'
					data.page = this.page
				//获取数据
				let url = ''
					//#ifdef MP-WEIXIN
					url = 'entry/wxapp/distribution'
					//#endif
					//#ifdef H5
					url = 'entry/site/distribution'
					//#endif
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							let list = res.data.data.data
							that.list = that.list.concat(list);
							//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
							that.mescroll.endSuccess(list.length);
							that.page = that.page + 1
						}
					}
				})
			},
			//下拉刷新
			downCallback: function() {
				let that = this
				this.page = 1
				let data = {}
					data.page = this.page
					data.action = 'orders'
				let url = ''
					//#ifdef MP-WEIXIN
					url = 'entry/wxapp/distribution'
					//#endif
					//#ifdef H5
					url = 'entry/site/orders'
					//#endif	
				//获取数据
				this.util.request({
					url : url,
					data : data,
					success: function (res) {
						if (res.data.code == 200) {
							that.list = []
							that.list = res.data.data.data
							//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
							that.mescroll.endSuccess(that.list.length);
							that.page = 2
						}
					}
				})
			},
			
		}
	}
</script>

<style lang="scss">
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #f8f8f8;
		min-height: 100%;
		height: auto;
	}
	
	.list {
		/*小图*/
		padding: 0 10rpx;
		display: block;
	
		.item {
			box-sizing:border-box;
			background-color: #fff;
			margin: 10rpx;
			border-radius: 10rpx;
			box-shadow: 0 0 10rpx rgba(0,0,0,.02);
			overflow: hidden;
			.base-info {
				display: flex;
				font-size: 28rpx;
				border-bottom: 2rpx solid #eee;
				line-height: 64rpx;
				color: #666;
				padding: 0 20rpx;
				.orderno {
					flex: 1;
				}
				.evaluate {
					width: 120rpx;
					text-align: center;
				}
			}
			.content {
				display: flex;
				padding: 20rpx;
				.cover {
					width: 280rpx;
					overflow: hidden;
					.image {
						border-radius: 10rpx;
						width: 100%;
						height: auto;
						display: block;
					}
				}
				.info {
					flex: 1;
					padding: 0 0 0 20rpx;
					.title {
						font-size: 28rpx;
						color: #000;
						font-weight: 600;
						height: 72rpx;
						line-height: 36rpx;
					}
					.description {
						color: #999;
						font-size: 12px;
					}
					.price {
						margin-top: 20rpx;
						font-size: 28rpx;
						text-align: right;
						.value {
							font-weight: 700;
						}
					}
					.exp-info {
						margin-top: 10rpx;
						color: #999;
						font-size: 24rpx;
						.item {
							display: inline;
							margin: 0;
							.num {
								margin: 0 10rpx;
							}
						}
					}
				}
			}
			.pay-info {
				border-top: 2rpx solid #eee;
				line-height: 64rpx;
				color: #666;
				padding: 0 20rpx;
				.pay-yes {
					display: flex;
					font-size: 28rpx;
					.paid-price {
						flex: 1;
					}
					.paid-time {
						width: 440rpx;
						text-align: right;
					}
					.pay-btn {
						width: 300rpx;
						
						button {
							display: block;
							margin: 6rpx auto;
							font-size: 24rpx;
							color: #fff;
						}
					}
				}
			}
		}
	}
	/*页面风格设计*/
	.Blue {
		.price {
			.value {
				color: $Blue;
			}
		}
	}
	.Green {
		.price {
			.value {
				color: $Green;
			}
		}
	}
	.LightRed {
		.price {
			.value {
				color: $LightRed;
			}
		}
	}
	.Orange {
		.price {
			.value {
				color: $Orange;
			}
		}
	}
	.LightPink {
		.price {
			.value {
				color: $LightPink;
			}
		}
	}
	.Magenta {
		.price {
			.value {
				color: $Magenta;
			}
		}
	}
</style>
